
function showCategoryList(id,catname) {
  // article_detail.html
  console.log('showCategoryList'+id);
  if(id == 0) {
    api.openFrame({
        name: 'specimen_index',
        softInputMode: 'pan',
        url: 'widget://html/specimen_index.html',
        rect: {
            x: 0,
            y: 0,
            w: 'auto',
            h: 'auto'
        }
    })
  } else {
    api.openFrame({
        name: 'specimen_secondary_classification'+id,
        softInputMode: 'pan',
        url: 'widget://html/specimen_secondary_classification.html',
        rect: {
            x: 0,
            y: 0,
            w: 'auto',
            h: 'auto'
        },
        pageParam: {
            catid: id,
            catname: catname
        }
    })
  }
}
function showRockList(id, catname) {
  // article_detail.html
  console.log('showRockList'+id);
  api.openFrame({
      name: 'specimen_three_level_classification'+id,
      softInputMode: 'pan',
      url: 'widget://html/specimen_three_level_classification.html',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      },
      pageParam: {
          catid: id,
          catname: catname
      }
  })
}
function showRock(id) {
  // article_detail.html
  console.log('showRock'+id);
  api.openFrame({
      name: 'specimen_detail'+id,
      softInputMode: 'pan',
      url: 'widget://html/specimen_detail.html',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      },
      pageParam: {
          rockid: id
      }
  })
}
function goToIndex() {
  api.openFrame({
      name: 'index',
      url: 'widget://html/index.html',
      softInputMode: 'pan',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      }
  })
}
function goToArticleList() {
  api.openFrame({
      name: 'article_list',
      url: 'widget://html/article_list.html',
      softInputMode: 'pan',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      }
  })
}
function goToWin(win) {
  api.openFrame({
      name: win,
      url: 'widget://html/'+win+'.html',
      softInputMode: 'pan',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      }
  })
}
function showDetail(id) {
  // article_detail.html
  api.openFrame({
      name: 'article_detail_'+id,
      url: 'article_detail.html',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      },
      pageParam: {
          id: id,
      }
  })
}
function goBack() {
  api.closeFrame();
}
function showNav(cate, lastCid, currentId) {
  var str = '';
  str += '<span onclick="goToIndex()" class="position-item-title">首页</span>';
  str += ' <span class="position-item-icon"> > </span> <span onclick="showCategoryList(0)" class="position-item-title">标本</span>';
  for(o in cate) {
    if(lastCid == o) {
      // 是最终分类
      if(currentId == o) {
        str += ' <span class="position-item-icon"> > </span> <span class="position-item-title current">'+cate[o]+'</span>';
      } else {
        str += ' <span class="position-item-icon"> > </span> <span onclick="showRockList('+o+')" class="position-item-title">'+cate[o]+'</span>';
      }
    } else {
      if(currentId == o) {
        str += ' <span class="position-item-icon"> > </span> <span class="position-item-title current">'+cate[o]+'</span>';
      } else {
        str += ' <span class="position-item-icon"> > </span> <span onclick="showCategoryList('+o+')" class="position-item-title">'+cate[o]+'</span>';
      }
    }
  }
  $('#nav').html(str);
  console.log(str);
}
$('#search-icon').click(function(e){
  goToSearch();
})
$("#search-input").keypress(function (e) {
  if (e.which == 13) {
    goToSearch();
  }
});
function goToSearch() {
  api.closeFrame({
    name:'search'
  })
  // ReloadData();
  var keywords = $('#search-input').val();
  if(keywords == '') {
    api.toast({
      msg:"请输入要搜索的内容"
    })
    return false;
  }
  $('#search-input').val('');
  $('#search-input').blur();
  // api.closeFrame({
  //   name:'search'
  // })
  api.openFrame({
    name: 'search',
    url: 'widget://html/search_index.html',
    softInputMode: 'pan',
    rect: {
      x: 0,
      y: 0,
      w: 'auto',
      h: 'auto'
    },
    pageParam: {
        keywords: keywords
    }
  });
}
